package com.yanqu.road.server.cmd.activity.gourdchild;

import com.yanqu.road.entity.activity.gourdchild.GourdChildConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.GourdChildProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.gourdchild.GourdChildModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.gourdchild.GourdChildMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = GameProtocol.S_GOURD_CHILD_FAST_THROUGH, desc = "快速通关")
public class GourdChildFastThroughCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        GourdChildConfig config = GourdChildMgr.getConfig();
        if (config == null || !ActivityMgr.activityInTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_GOURD_CHILD_ACTIVITY_NO_OPEN;
            return;
        }

        GourdChildProto.GourdChildFastThroughReqMsg reqMsg = GourdChildProto.GourdChildFastThroughReqMsg.parseFrom(packet.getBytes());

        ret = player.getModule(GourdChildModule.class).fastPass(reqMsg.getPassId());
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_GOURD_CHILD_FAST_THROUGH, GourdChildProto.GourdChildFastThroughRespMsg.newBuilder().setRet(ret));
        }
    }
}
